package Day2025_03_02;

import java.util.HashMap;
import java.util.Map;

public class LeetCode219 {
    public boolean containsNearbyDuplicate(int[] nums, int k) {
        Map<Integer, Integer> hash = new HashMap<>();
        int n = nums.length;
        for (int i = 0; i < n; i++) {
            if (hash.containsKey(nums[i]) && i - hash.get(nums[i]) <= k) return true;
            hash.put(nums[i], i);
        }
        return false;
    }
}
